/**
<code>
  <author name="Zealic" email="zealic(at)gmail.com" type="Creator"/>
</code>
**/
using System;
using System.Net;
using System.Net.NetworkInformation;


namespace Zealib.Win32.Network
{
    /// <summary>
    /// TCP connection infomation
    /// </summary>
    public sealed class TcpConnectionInfo : IEquatable<TcpConnectionInfo>
    {
        private readonly IPEndPoint _LocalEndPoint;
        private readonly IPEndPoint _RemoteEndPoint;
        private readonly TcpState _State;

        public TcpConnectionInfo(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, TcpState state)
        {
            if (localEndPoint == null) throw new ArgumentNullException("localEndPoint");
            if (remoteEndPoint == null) throw new ArgumentNullException("remoteEndPoint");
            _LocalEndPoint = localEndPoint;
            _RemoteEndPoint = remoteEndPoint;
            _State = state;
        }

        public IPEndPoint LocalEndPoint
        {
            get { return _LocalEndPoint; }
        }

        public IPEndPoint RemoteEndPoint
        {
            get { return _RemoteEndPoint; }
        }

        public TcpState State
        {
            get { return _State; }
        }

        public override int GetHashCode()
        {
            return LocalEndPoint.GetHashCode() ^ RemoteEndPoint.GetHashCode();
        }

        public bool Equals(TcpConnectionInfo other)
        {
            return Equals(this, other);
        }

        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is TcpConnectionInfo))
                return false;
            return Equals(this, obj);
        }

    }
}